﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PTA.Db;
namespace PTA.TreeHelper
{
    public class TreeNode<N> : BaseEntity
        where N : TreeNode<N>
    {
        private TreeNode<N> parent = null;
        private List<N> nodes = new List<N>();
        private int nodeLevel = 0;

        public void Add(N node)
        {
            node.parent = this;
            node.nodeLevel = this.nodeLevel + 1;
            this.nodes.Add(node);
        }

        public List<N> ChildNodes
        {
            get
            {
                return this.nodes;
            }
        }

        public TreeNode<N> Parent
        {
            get
            {
                return parent;
            }
        }

        public string Text
        {
            get;
            set;
        }

        public int NodeLevel
        {
            get
            {
                return this.nodeLevel;
            }
        }
    }

    public class TreeView<N> where N : TreeNode<N>
    {
        private List<N> nodes = new List<N>();

        public List<N> Nodes
        {
            get
            {
                return nodes;
            }
        }

        public void Add(N node)
        {
            this.nodes.Add(node);
        }
    }


    public abstract class BaseTreeNode : BaseEntity
    {
        [Column(PrimaryKey = true, Identity = true, SequenceName = "NodeIdSequence")]
        public virtual int NodeId { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select | BindingFlag.Update)]
        public string NodeName { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select)]
        public int NodeLevel { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select)]
        public int ParentId { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select)]
        public List<int> ParentList { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select)]
        public int ChildCount { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select)]
        public int OrderId { get; set; }

        [Column(Flag = Db.BindingFlag.Insert | BindingFlag.Select)]
        public int OwnerId { get; set; }
    }

    /// <summary>
    /// 树节点的移动方向
    /// </summary>
    public enum MoveDirection
    {
        向上移动 = 1,

        上移至顶 = 2,

        向下移动 = 3,

        下移至底 = 4,

        向左移动 = 5,

        向右移动 = 6,
    }
}
